package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.xcity.game.item.Bag;
import com.xcity.game.item.GameItem;
import com.xcity.game.item.ItemTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class BagInfoResponse extends Response {

	private int gridSize; // 背包格子数
	private List<ItemInfo> items;
	
	public static class ItemInfo {
		public long id; // 物品实例id
		public int itemId; // 物品模板id
		public int count;
		public byte target;
		public byte type;
		public int effect; // 物品效果
		public String name;
		public String desc;
		public String icon;
		public byte quality;
		public ItemInfo(GameItem ref) {
			ItemTemplate template = ref.getTemplate();
			this.id = ref.getId();
			this.itemId = template.getId();
			this.count = ref.getCount();
			this.target = template.getTarget();
			this.type = template.getType();
			this.effect = template.getEffect();
			this.name = template.getName();
			this.desc = template.getDesc();
			this.icon = template.getIcon();
			this.quality = template.getQuality();
		}
	}
	
	public BagInfoResponse(int serial, Bag bag) {
		super(serial);
		List<GameItem> items = bag.getItems();
		if (items == null || items.isEmpty()) {
			this.items = Collections.emptyList();
			return;
		}
		List<ItemInfo> list = new ArrayList<ItemInfo>(items.size());
		for (int i = 0; i < items.size(); i++) {
			GameItem item = items.get(i);
			ItemInfo info = new ItemInfo(item);
			list.add(info);
		}
		this.items = list;
		this.gridSize = bag.getMaxGridSize();
	}

	public int getGridSize() {
		return gridSize;
	}

	public void setGridSize(int gridSize) {
		this.gridSize = gridSize;
	}

	public List<ItemInfo> getItems() {
		return items;
	}

	public void setItems(List<ItemInfo> items) {
		this.items = items;
	}
	
}
